package com.chinasofti.service;

import com.chinasofti.dao.StudentDao;
import com.chinasofti.dao.StudentDaoImpl;
import com.chinasofti.domain.Student;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;

public class StudentService {
    StudentDao dao = new StudentDaoImpl();
    @Test
    public void testfidall(){
        ArrayList<Student> all = dao.findAll();
        all.stream().forEach(System.out::println);
//        for (Student student : all) {
//            System.out.println(student);
//        }
    }
    @Test
    public void testInsertStudent(){
        Student student = new Student(null,"周七",27,new Date());
        int r = dao.insert(student);
        if (r != 0){
            System.out.println("新增成功");
        }else {
            System.out.println("新增失败");
        }
    }
    @Test
    public void testUpdateStudent() {
        Student student = new Student(1, "张三1", 22, new Date());
        int r = dao.update(student);
        if (r != 0) {
            System.out.println("修改成功");
        } else {
            System.out.println("修改失败");
        }
    }
    @Test
    public void testdeleteStudent(){
        int s = (int) dao.delete(4);
        if(s !=0){
            System.out.println("删除成功");
        }else{
            System.out.println("删除失败");
        }
    }
    @Test
    public void testFindById(){
        Student stu = dao.findById(1);
        System.out.println("stu = " + stu);
    }
}
